package com.jrx.anytxn.transaction.service;

import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.common.exception.TxnException;
import com.jrx.anytxn.transaction.bean.LoanParamBean;
import com.jrx.anytxn.transaction.dto.loan.LoanConfirmReq;
import com.jrx.anytxn.transaction.entity.AmLoanMainInfo;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 贷款信息service
 *
 * @author : zhenghaopu
 * 2019/10/22
 */
public interface ILoanMainInfoService {

    /**
     * 根据订单ID，渠道号，客户ID查询订单信息
     *
     * @param loanId     贷款ID
     * @param customerId 客户ID
     * @param tenantId   租户ID
     * @return com.jrx.anytxn.transaction.dto.common.LoanMainInfoRes
     * @author fan.yang
     * date: 2019/9/25 0025 上午 11:25
     */
    AmLoanMainInfo getAmLoanMainInfoByLoanIdAndCusId(String loanId, String customerId, String tenantId) throws TxnBizException;

    /**
     * 根据订单ID/外部合同号与用户号查询订单信息
     * 禁止controller调用
     *
     * @param loanId         订单id
     * @param contractNumber 合同号
     * @param cusId          客户id
     * @param tenantId       租户ID
     * @return 订单信息
     * @author zhenghaopu
     * date: 2019/9/25 9:59
     */
    AmLoanMainInfo findLoanMainInfoByLoanIdOrContractNumber(String loanId, String contractNumber, String cusId,
                                                            String tenantId, String channel) throws TxnBizException;

    /**
     * 构建贷款信息
     *
     * @param loanParamBean  贷款参数
     * @param loanConfirmReq 贷款请求
     * @return
     */
    AmLoanMainInfo buildLoanMainInfo(LoanParamBean loanParamBean, LoanConfirmReq loanConfirmReq, Date businessDate) throws TxnException;

    /**
     * 统计 当周 周一至周四 客户 某交易类型总额
     *
     * @param customerId
     * @param loanType
     * @return
     */
    BigDecimal sumByCustomerIdAndLoanTypeFromMondayToThursdayCurrentWeek(String customerId, String loanType, String tenantId, String productId);

    /**
     * 统计当月某交易类型总额
     *
     * @param customerId
     * @param loanType
     * @param tenantId
     * @return
     */
    BigDecimal sumByCustomerIdAndLoanTypeMonthly(String customerId, String loanType, String tenantId, String productId);

    /**
     * 统计指定时间区间内消费总额大于指定值的总数（按客户id维度统计）
     *
     * @param tenantId  租户号
     * @param startTime 生效时间
     * @param endTime   失效时间
     * @param loanType  借据类型
     * @param sumAmount 总额值
     * @return
     */
    Integer countDistinctlyGroupByCustomerId(String tenantId, String startTime, String endTime, String loanType, BigDecimal sumAmount, String productId);

    /**
     * 根据租户号、客户号、借据类型查找记录
     *
     * @param tenantId
     * @param customerId
     * @param loanType
     * @return
     */
    List<AmLoanMainInfo> listByCustomerIdAndLoanType(String tenantId, String customerId, String loanType, String productId);

    /**
     * @param startTime
     * @param endTime
     * @param loanType
     * @param sumAmount
     * @return
     */
    List<String> getAmLoanMainInfoByConsumeAmountWeekly(String startTime, String endTime, String loanType, BigDecimal sumAmount, String productId);
}
